Skip to content

fix: do not index WP_Error when polling optimized images - #1134

Open
selul wants to merge 1 commit into
developmentfrom
fix/1125-poll-optimized-images-wp-error
Open

fix: do not index WP_Error when polling optimized images#1134
selul wants to merge 1 commit into
developmentfrom
fix/1125-poll-optimized-images-wp-error

Conversation

@selul

@selul selul commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Dashboard optimized-images polling called get_optimized_images(), which is documented to return array|bool|WP_Error, then indexed $images['list'] with no type check. Transport failures and non-200 API error payloads therefore fatal with Cannot use object of type WP_Error as array (inc/rest.php:712).
  • Treat WP_Error, non-arrays, and missing/empty lists the same as “no images”: return a successful REST payload with an empty list so the dashboard widget degrades instead of crashing.
  • Covers the 4.2.11 telemetry in Optimized-images polling crashes on WP_Error responses #1125 (3 sites). This is a standing type hole, not an update/OPcache race.

Fixes #1125

Test plan

  • composer phpunit -- --filter=Test_Poll_Optimized_Images (transport WP_Error, API error payload, empty body, missing/empty list, successful list)
  • PHPCS on inc/rest.php, PHPStan
  • In the dashboard, with Optimole disconnected from the stats API / blocked HTTP, Last optimized images should stay empty instead of a REST 500
  • With a working connection, the last-optimized-images widget still lists images

Made with Cursor

get_optimized_images() can return WP_Error or false on transport and API failures. Guard poll_optimized_images() so dashboard polling degrades to an empty list instead of fatalling.

Co-authored-by: Cursor <cursoragent@cursor.com>
@pirate-bot

Copy link
Copy Markdown
Collaborator

Plugin build for cf37264 is ready 🛎️!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants